package com.example.navigationdemo2

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class MyViewModel :ViewModel(){
    private  var index:MutableLiveData<Int>?=null

    fun getIndex():MutableLiveData<Int>{
        if (index==null){
            index=MutableLiveData<Int>()
            index!!.value=0
        }
        return index as MutableLiveData<Int>
    }
    fun add(n:Int){
        index!!.value=index!!.value!!.plus(n)
    }
}